package com.esms.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.esms.po.KeyValue;
import com.esms.service.impl.KeyValueServiceImpl;
import com.esms.utils.Message;

@Controller
public class KeyValueController {
	@Autowired
	private KeyValueServiceImpl keyValueService = null;

	@RequestMapping("/changeWageItem.do")
	@ResponseBody
	public Message changeWageItem(Integer id,double late_buckle_pay,double early_buckle_pay,double missionallowance,double full_attendance_pay,double food_pay,double traffic_pay)throws Exception{
		if(id==null) {
			KeyValue kv1=new KeyValue();
			kv1.setKvKey("food_pay");
			kv1.setKvValue(food_pay);
			keyValueService.insert(kv1);
			KeyValue kv2=new KeyValue();
			kv2.setKvKey("traffic_pay");
			kv2.setKvValue(traffic_pay);
			keyValueService.insert(kv2);
			KeyValue kv3=new KeyValue();
			kv3.setKvKey("late_buckle_pay");
			kv3.setKvValue(late_buckle_pay);
			keyValueService.insert(kv3);
			KeyValue kv4=new KeyValue();
			kv4.setKvKey("early_buckle_pay");
			kv4.setKvValue(early_buckle_pay);
			keyValueService.insert(kv4);
			KeyValue kv5=new KeyValue();
			kv5.setKvKey("missionallowance");
			kv5.setKvValue(missionallowance);
			keyValueService.insert(kv5);
			KeyValue kv6=new KeyValue();
			kv6.setKvKey("full_attendance_pay");
			kv6.setKvValue(full_attendance_pay);
			keyValueService.insert(kv6);
		}else {
			KeyValue kv1=new KeyValue();
			kv1.setKvKey("food_pay");
			kv1.setKvId(12);
			kv1.setKvValue(food_pay);
			keyValueService.updateByPrimaryKey(kv1);

			KeyValue kv2=new KeyValue();
			kv2.setKvId(13);
			kv2.setKvKey("traffic_pay");
			kv2.setKvValue(traffic_pay);
			keyValueService.updateByPrimaryKey(kv2);

			KeyValue kv3=new KeyValue();
			kv3.setKvId(14);
			kv3.setKvKey("late_buckle_pay");
			kv3.setKvValue(late_buckle_pay);
			keyValueService.updateByPrimaryKey(kv3);

			KeyValue kv4=new KeyValue();
			kv4.setKvId(15);
			kv4.setKvKey("early_buckle_pay");
			kv4.setKvValue(early_buckle_pay);
			keyValueService.updateByPrimaryKey(kv4);

			KeyValue kv5=new KeyValue();
			kv5.setKvId(16);
			kv5.setKvKey("missionallowance");
			kv5.setKvValue(missionallowance);
			keyValueService.updateByPrimaryKey(kv5);

			KeyValue kv6=new KeyValue();
			kv6.setKvId(17);
			kv6.setKvKey("full_attendance_pay");
			kv6.setKvValue(full_attendance_pay);
			keyValueService.updateByPrimaryKey(kv6);
		}
		
		

		return Message.success("添加成功");
	}
	/**
	 * 获取工资项
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getAllWageItem.do")
	public Map<String,Object> getAllWageItem(){
		Map<String, Object> ret = new HashMap<String,Object>();
		List<KeyValue> findList = keyValueService.findList();
		ret.put("type", "success");
		ret.put("data", findList);
		return ret;
	}
	


}
